package com.hui.service;

import com.hui.entity.Orders;
import com.hui.mapper.OrderMapper;
import com.hui.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/09/17/8:25
 * @Description:
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Orders getOrderById(Integer id) {
        return orderMapper.selectById(id);
    }

    @Override
    public Map<String, Object> getOrderByCondition(OrderVo orderVo) {
        Map<String, Object> map = new HashMap<>();
        // 查询总行数
        Integer integer = orderMapper.selectCount(null);
        // 分页查询,设置偏移量
        orderVo.setOffset((orderVo.getPageNo() - 1) * orderVo.getPageSize());
        List<Orders> ordersList=orderMapper.getOrderByCondition(orderVo);
        // 封装数据
        map.put("total", integer);
        map.put("list", ordersList);
        return map;
    }
}
